'''
Created on 11.11.2009

@author: adelgald
'''

import os
import sys

def readKey(filename, key):
    try:
        file_handler = open(filename,"r")
        for line in file_handler.readlines():
            if (line.find(key) != -1) and (line[0] != "#"):
                value = line[line.find("=")+1:]
                if (value.find('\n') != -1):
                    value = value[:len(value)-1]
                if (value.find('\r') != -1):
                    value = value[:len(value)-1]
                value = value.strip()
                
        file_handler.close()
        return value
    except:
        return False

def getConfig(filename):
    try:
        config = {} 
        
        config['source_folder'] = readKey(filename, "source_folder")
        config['target_folder'] = readKey(filename, "target_folder")

        config['log_level']     = readKey(filename,"log_level")
        config['log_filename']  = readKey(filename,"log_filename")
        
        return config
    except:
        return False